
import os
from whiff.middleware import misc

class showPage(misc.utility):
    def __init__(self, page):
        self.page = page
    def __call__(self, env, start_response):
        filename = self.param_value(self.page, env)
        if filename.find("..")>=0 or "/" in filename:
            raise ValueError, "no paths please "+repr(filename)
        (mydir, myfile) = os.path.split(__file__)
        filepath = os.path.join(mydir, filename) + ".whiff"
        filetext = file(filepath).read()
        start_response("200 OK", [('Content-Type', "text/plain")])
        return [filetext]

__middleware__ = showPage

if __name__=="__main__":
    app = showPage("W1200_1300.applicationAPI")
    r = app({}, misc.ignore)
    t = "".join(list(r))
    print "test result"
    print t
